package br.ucb.sigplan.action.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.sigplan.action.Action;
import br.ucb.sigplan.beans.Login;
import br.ucb.sigplan.beans.Turma;
import br.ucb.sigplan.crud.TurmaCrud;

public class AbrirListarTurmaAction implements Action {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Login login = (Login) req.getSession().getAttribute("login");
		List<Turma> turmas = TurmaCrud.findAll();
		if (turmas.isEmpty()) {
			req.setAttribute("msg", "turmasVazia");
			return "/jsp/index.jsp";
		}
		req.setAttribute("turmas", turmas);	
		if (login.getTipo().getValue() == 'P') {
			return "/jsp/professor/turma/listagemTurma.jsp";
		}else {
			return "/jsp/diretor/turma/dirListaTurmas.jsp";
		}
	}

}
